home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / JPopupMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  19.0 KB  |  949 lines

  1. package javax.swing;
  2.  
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dialog;
  6. import java.awt.Dimension;
  7. import java.awt.Frame;
  8. import java.awt.Graphics;
  9. import java.awt.Insets;
  10. import java.awt.Point;
  11. import java.awt.Rectangle;
  12. import java.awt.Window;
  13. import java.awt.event.KeyEvent;
  14. import java.awt.event.MouseEvent;
  15. import java.beans.PropertyChangeListener;
  16. import java.io.IOException;
  17. import java.io.ObjectInputStream;
  18. import java.io.ObjectOutputStream;
  19. import java.io.Serializable;
  20. import java.util.Hashtable;
  21. import java.util.Vector;
  22. import javax.accessibility.Accessible;
  23. import javax.accessibility.AccessibleContext;
  24. import javax.accessibility.AccessibleState;
  25. import javax.swing.event.PopupMenuEvent;
  26. import javax.swing.event.PopupMenuListener;
  27. import javax.swing.plaf.PopupMenuUI;
  28.  
  29. public class JPopupMenu extends JComponent implements Accessible, MenuElement {
  30.    private static final String uiClassID = "PopupMenuUI";
  31.    transient Component invoker;
  32.    transient Popup popup;
  33.    transient Frame frame;
  34.    private String label;
  35.    private boolean paintBorder;
  36.    private Insets margin;
  37.    private int desiredLocationX;
  38.    private int desiredLocationY;
  39.    private int lastPopupType;
  40.    private static final Object heavyPopupCacheKey = new StringBuffer("JPopupMenu.heavyPopupCache");
  41.    private static final Object lightPopupCacheKey = new StringBuffer("JPopupMenu.lightPopupCache");
  42.    private static final Object mediumPopupCacheKey = new StringBuffer("JPopupMenu.mediumPopupCache");
  43.    private static final Object defaultLWPopupEnabledKey = new StringBuffer("JPopupMenu.defaultLWPopupEnabledKey");
  44.    private static final int MAX_CACHE_SIZE = 5;
  45.    private boolean lightWeightPopupEnabled;
  46.    private static final int LIGHT_WEIGHT_POPUP = 0;
  47.    private static final int MEDIUM_WEIGHT_POPUP = 1;
  48.    private static final int HEAVY_WEIGHT_POPUP = 2;
  49.    private SingleSelectionModel selectionModel;
  50.    private static Hashtable listenerRegistry = null;
  51.    private static final Object classLock = new Object();
  52.    // $FF: synthetic field
  53.    static Class class$javax$swing$event$PopupMenuListener;
  54.  
  55.    public JPopupMenu() {
  56.       this((String)null);
  57.    }
  58.  
  59.    public JPopupMenu(String var1) {
  60.       this.label = null;
  61.       this.paintBorder = true;
  62.       this.margin = null;
  63.       this.lastPopupType = 0;
  64.       this.lightWeightPopupEnabled = true;
  65.       this.label = var1;
  66.       this.lightWeightPopupEnabled = getDefaultLightWeightPopupEnabled();
  67.       this.setSelectionModel(new DefaultSingleSelectionModel());
  68.       ((Component)this).addMouseListener(new 2());
  69.       this.updateUI();
  70.    }
  71.  
  72.    // $FF: synthetic method
  73.    static Hashtable access$0() {
  74.       return getHeavyPopupCache();
  75.    }
  76.  
  77.    public JMenuItem add(String var1) {
  78.       return this.add(new JMenuItem(var1));
  79.    }
  80.  
  81.    public JMenuItem add(Action var1) {
  82.       JMenuItem var2 = new JMenuItem((String)var1.getValue("Name"), (Icon)var1.getValue("SmallIcon"));
  83.       ((AbstractButton)var2).setHorizontalTextPosition(4);
  84.       ((AbstractButton)var2).setVerticalTextPosition(0);
  85.       var2.setEnabled(var1.isEnabled());
  86.       ((AbstractButton)var2).addActionListener(var1);
  87.       this.add(var2);
  88.       this.registerMenuItemForAction(var2, var1);
  89.       return var2;
  90.    }
  91.  
  92.    public JMenuItem add(JMenuItem var1) {
  93.       super.add(var1);
  94.       return var1;
  95.    }
  96.  
  97.    public void addPopupMenuListener(PopupMenuListener var1) {
  98.       super.listenerList.add(class$javax$swing$event$PopupMenuListener != null ? class$javax$swing$event$PopupMenuListener : (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")), var1);
  99.    }
  100.  
  101.    public void addSeparator() {
  102.       ((Container)this).add(new Separator());
  103.    }
  104.  
  105.    boolean alwaysOnTop() {
  106.       return true;
  107.    }
  108.  
  109.    private boolean ancestorIsModalDialog(Component var1) {
  110.       Object var2 = null;
  111.       if (var1 != null) {
  112.          for(Container var3 = var1.getParent(); var3 != null; var3 = ((Component)var3).getParent()) {
  113.             if (var3 instanceof Dialog && ((Dialog)var3).isModal()) {
  114.                return true;
  115.             }
  116.          }
  117.       }
  118.  
  119.       return false;
  120.    }
  121.  
  122.    // $FF: synthetic method
  123.    static Class class$(String var0) {
  124.       try {
  125.          return Class.forName(var0);
  126.       } catch (ClassNotFoundException var2) {
  127.          throw new NoClassDefFoundError(((Throwable)var2).getMessage());
  128.       }
  129.    }
  130.  
  131.    protected PropertyChangeListener createActionChangeListener(JMenuItem var1) {
  132.       return new ActionChangedListener(this, var1);
  133.    }
  134.  
  135.    private Popup createHeavyWeightPopup() {
  136.       Frame var1 = getFrame(this.invoker);
  137.       if (var1 != null) {
  138.          this.popup = getRecycledHeavyPopup(var1);
  139.       } else {
  140.          var1 = new Frame();
  141.       }
  142.  
  143.       if (this.popup == null) {
  144.          this.popup = new WindowPopup(this, var1);
  145.       }
  146.  
  147.       return this.popup;
  148.    }
  149.  
  150.    private Popup createLightWeightPopup() {
  151.       Object var1 = getRecycledLightPopup();
  152.       if (var1 == null) {
  153.          var1 = new JPanelPopup(this);
  154.       }
  155.  
  156.       return (Popup)var1;
  157.    }
  158.  
  159.    private Popup createMediumWeightPopup() {
  160.       Object var1 = getRecycledMediumPopup();
  161.       if (var1 == null) {
  162.          var1 = new PanelPopup(this);
  163.       }
  164.  
  165.       return (Popup)var1;
  166.    }
  167.  
  168.    protected void firePopupMenuCanceled() {
  169.       Object[] var1 = super.listenerList.getListenerList();
  170.       PopupMenuEvent var2 = null;
  171.  
  172.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  173.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener != null ? class$javax$swing$event$PopupMenuListener : (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")))) {
  174.             if (var2 == null) {
  175.                var2 = new PopupMenuEvent(this);
  176.             }
  177.  
  178.             ((PopupMenuListener)var1[var3 + 1]).popupMenuCanceled(var2);
  179.          }
  180.       }
  181.  
  182.    }
  183.  
  184.    protected void firePopupMenuWillBecomeInvisible() {
  185.       Object[] var1 = super.listenerList.getListenerList();
  186.       PopupMenuEvent var2 = null;
  187.  
  188.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  189.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener != null ? class$javax$swing$event$PopupMenuListener : (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")))) {
  190.             if (var2 == null) {
  191.                var2 = new PopupMenuEvent(this);
  192.             }
  193.  
  194.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeInvisible(var2);
  195.          }
  196.       }
  197.  
  198.    }
  199.  
  200.    protected void firePopupMenuWillBecomeVisible() {
  201.       Object[] var1 = super.listenerList.getListenerList();
  202.       PopupMenuEvent var2 = null;
  203.  
  204.       for(int var3 = var1.length - 2; var3 >= 0; var3 -= 2) {
  205.          if (var1[var3] == (class$javax$swing$event$PopupMenuListener != null ? class$javax$swing$event$PopupMenuListener : (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")))) {
  206.             if (var2 == null) {
  207.                var2 = new PopupMenuEvent(this);
  208.             }
  209.  
  210.             ((PopupMenuListener)var1[var3 + 1]).popupMenuWillBecomeVisible(var2);
  211.          }
  212.       }
  213.  
  214.    }
  215.  
  216.    public AccessibleContext getAccessibleContext() {
  217.       if (super.accessibleContext == null) {
  218.          super.accessibleContext = new AccessibleJPopupMenu(this);
  219.       }
  220.  
  221.       return super.accessibleContext;
  222.    }
  223.  
  224.    public Component getComponent() {
  225.       return this;
  226.    }
  227.  
  228.    public Component getComponentAtIndex(int var1) {
  229.       return ((Container)this).getComponent(var1);
  230.    }
  231.  
  232.    public int getComponentIndex(Component var1) {
  233.       int var2 = ((Container)this).getComponentCount();
  234.       Component[] var3 = ((Container)this).getComponents();
  235.  
  236.       for(int var4 = 0; var4 < var2; ++var4) {
  237.          Component var5 = var3[var4];
  238.          if (var5 == var1) {
  239.             return var4;
  240.          }
  241.       }
  242.  
  243.       return -1;
  244.    }
  245.  
  246.    public static boolean getDefaultLightWeightPopupEnabled() {
  247.       Boolean var0 = (Boolean)SwingUtilities.appContextGet(defaultLWPopupEnabledKey);
  248.       if (var0 == null) {
  249.          SwingUtilities.appContextPut(defaultLWPopupEnabledKey, Boolean.TRUE);
  250.          return true;
  251.       } else {
  252.          return var0;
  253.       }
  254.    }
  255.  
  256.    private static Frame getFrame(Component var0) {
  257.       Object var1;
  258.       for(var1 = var0; !(var1 instanceof Frame) && var1 != null; var1 = ((Component)var1).getParent()) {
  259.       }
  260.  
  261.       return (Frame)var1;
  262.    }
  263.  
  264.    private static Hashtable getHeavyPopupCache() {
  265.       Hashtable var0 = (Hashtable)SwingUtilities.appContextGet(heavyPopupCacheKey);
  266.       if (var0 == null) {
  267.          var0 = new Hashtable(2);
  268.          SwingUtilities.appContextPut(heavyPopupCacheKey, var0);
  269.       }
  270.  
  271.       return var0;
  272.    }
  273.  
  274.    public Component getInvoker() {
  275.       return this.invoker;
  276.    }
  277.  
  278.    public String getLabel() {
  279.       return this.label;
  280.    }
  281.  
  282.    private static Vector getLightPopupCache() {
  283.       Vector var0 = (Vector)SwingUtilities.appContextGet(lightPopupCacheKey);
  284.       if (var0 == null) {
  285.          var0 = new Vector();
  286.          SwingUtilities.appContextPut(lightPopupCacheKey, var0);
  287.       }
  288.  
  289.       return var0;
  290.    }
  291.  
  292.    public Insets getMargin() {
  293.       return this.margin == null ? new Insets(0, 0, 0, 0) : this.margin;
  294.    }
  295.  
  296.    private static Vector getMediumPopupCache() {
  297.       Vector var0 = (Vector)SwingUtilities.appContextGet(mediumPopupCacheKey);
  298.       if (var0 == null) {
  299.          var0 = new Vector();
  300.          SwingUtilities.appContextPut(mediumPopupCacheKey, var0);
  301.       }
  302.  
  303.       return var0;
  304.    }
  305.  
  306.    static Popup getRecycledHeavyPopup(Frame var0) {
  307.       Object var2 = classLock;
  308.       synchronized(var2){}
  309.  
  310.       Popup var1;
  311.       try {
  312.          Hashtable var5 = getHeavyPopupCache();
  313.          if (!var5.containsKey(var0)) {
  314.             var1 = null;
  315.             return var1;
  316.          }
  317.  
  318.          Vector var4 = (Vector)var5.get(var0);
  319.          if (var4.size() <= 0) {
  320.             var1 = null;
  321.             return var1;
  322.          }
  323.  
  324.          Popup var7 = (Popup)var4.elementAt(0);
  325.          var4.removeElementAt(0);
  326.          var1 = var7;
  327.       } catch (Throwable var9) {
  328.          throw var9;
  329.       }
  330.  
  331.       return var1;
  332.    }
  333.  
  334.    static Popup getRecycledLightPopup() {
  335.       Object var1 = classLock;
  336.       synchronized(var1){}
  337.  
  338.       Popup var0;
  339.       try {
  340.          Vector var3 = getLightPopupCache();
  341.          if (var3.size() <= 0) {
  342.             var0 = null;
  343.             return var0;
  344.          }
  345.  
  346.          Popup var5 = (Popup)var3.elementAt(0);
  347.          var3.removeElementAt(0);
  348.          var0 = var5;
  349.       } catch (Throwable var7) {
  350.          throw var7;
  351.       }
  352.  
  353.       return var0;
  354.    }
  355.  
  356.    static Popup getRecycledMediumPopup() {
  357.       Object var1 = classLock;
  358.       synchronized(var1){}
  359.  
  360.       Popup var0;
  361.       try {
  362.          Vector var3 = getMediumPopupCache();
  363.          if (var3.size() <= 0) {
  364.             var0 = null;
  365.             return var0;
  366.          }
  367.  
  368.          Popup var5 = (Popup)var3.elementAt(0);
  369.          var3.removeElementAt(0);
  370.          var0 = var5;
  371.       } catch (Throwable var7) {
  372.          throw var7;
  373.       }
  374.  
  375.       return var0;
  376.    }
  377.  
  378.    JPopupMenu getRootPopupMenu() {
  379.       JPopupMenu var1;
  380.       for(var1 = this; var1 != null && !var1.isPopupMenu() && var1.getInvoker() != null && var1.getInvoker().getParent() != null && var1.getInvoker().getParent() instanceof JPopupMenu; var1 = (JPopupMenu)var1.getInvoker().getParent()) {
  381.       }
  382.  
  383.       return var1;
  384.    }
  385.  
  386.    public SingleSelectionModel getSelectionModel() {
  387.       return this.selectionModel;
  388.    }
  389.  
  390.    public MenuElement[] getSubElements() {
  391.       Vector var2 = new Vector();
  392.       int var3 = ((Container)this).getComponentCount();
  393.  
  394.       for(int var4 = 0; var4 < var3; ++var4) {
  395.          Component var5 = ((Container)this).getComponent(var4);
  396.          if (var5 instanceof MenuElement) {
  397.             var2.addElement(var5);
  398.          }
  399.       }
  400.  
  401.       MenuElement[] var1 = new MenuElement[var2.size()];
  402.       int var7 = 0;
  403.  
  404.       for(int var6 = var2.size(); var7 < var6; ++var7) {
  405.          var1[var7] = (MenuElement)var2.elementAt(var7);
  406.       }
  407.  
  408.       return var1;
  409.    }
  410.  
  411.    public PopupMenuUI getUI() {
  412.       return (PopupMenuUI)super.ui;
  413.    }
  414.  
  415.    public String getUIClassID() {
  416.       return "PopupMenuUI";
  417.    }
  418.  
  419.    public void insert(Component var1, int var2) {
  420.       if (var2 < 0) {
  421.          throw new IllegalArgumentException("index less than zero.");
  422.       } else {
  423.          int var3 = ((Container)this).getComponentCount();
  424.          Vector var4 = new Vector();
  425.  
  426.          for(int var5 = var2; var5 < var3; ++var5) {
  427.             var4.addElement(((Container)this).getComponent(var2));
  428.             this.remove(var2);
  429.          }
  430.  
  431.          ((Container)this).add(var1);
  432.  
  433.          for(int var6 = 0; var6 < var4.size(); ++var6) {
  434.             ((Container)this).add((Component)var4.elementAt(var6));
  435.          }
  436.  
  437.       }
  438.    }
  439.  
  440.    public void insert(Action var1, int var2) {
  441.       throw new Error("void insert(Action, int) {} not yet implemented");
  442.    }
  443.  
  444.    private boolean invokerInHeavyWeightPopup(Component var1) {
  445.       if (var1 != null) {
  446.          for(Container var2 = var1.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
  447.             if (var2 instanceof WindowPopup) {
  448.                return true;
  449.             }
  450.  
  451.             if (var2 instanceof PanelPopup || var2 instanceof JPanelPopup) {
  452.                break;
  453.             }
  454.          }
  455.       }
  456.  
  457.       return false;
  458.    }
  459.  
  460.    public boolean isBorderPainted() {
  461.       return this.paintBorder;
  462.    }
  463.  
  464.    public boolean isLightWeightPopupEnabled() {
  465.       return this.lightWeightPopupEnabled;
  466.    }
  467.  
  468.    private boolean isPopupMenu() {
  469.       return this.invoker != null && !(this.invoker instanceof JMenu);
  470.    }
  471.  
  472.    boolean isSubPopupMenu(JPopupMenu var1) {
  473.       int var2 = ((Container)this).getComponentCount();
  474.       Component[] var3 = ((Container)this).getComponents();
  475.  
  476.       for(int var4 = 0; var4 < var2; ++var4) {
  477.          Component var5 = var3[var4];
  478.          if (var5 instanceof JMenu) {
  479.             JMenu var6 = (JMenu)var5;
  480.             JPopupMenu var7 = var6.getPopupMenu();
  481.             if (var7 == var1) {
  482.                return true;
  483.             }
  484.  
  485.             if (var7.isSubPopupMenu(var1)) {
  486.                return true;
  487.             }
  488.          }
  489.       }
  490.  
  491.       return false;
  492.    }
  493.  
  494.    public boolean isVisible() {
  495.       return this.popup != null ? this.popup.isShowing() : false;
  496.    }
  497.  
  498.    public void menuSelectionChanged(boolean var1) {
  499.       if (this.invoker instanceof JMenu) {
  500.          JMenu var2 = (JMenu)this.invoker;
  501.          if (var1) {
  502.             var2.setPopupMenuVisible(true);
  503.          } else {
  504.             var2.setPopupMenuVisible(false);
  505.          }
  506.       }
  507.  
  508.       if (this.isPopupMenu() && !var1) {
  509.          this.setVisible(false);
  510.       }
  511.  
  512.    }
  513.  
  514.    public void pack() {
  515.       if (this.popup != null) {
  516.          this.popup.pack();
  517.       }
  518.  
  519.    }
  520.  
  521.    protected void paintBorder(Graphics var1) {
  522.       if (this.isBorderPainted()) {
  523.          super.paintBorder(var1);
  524.       }
  525.  
  526.    }
  527.  
  528.    protected String paramString() {
  529.       String var1 = this.label != null ? this.label : "";
  530.       String var2 = this.paintBorder ? "true" : "false";
  531.       String var3 = this.margin != null ? this.margin.toString() : "";
  532.       String var4;
  533.       if (this.lastPopupType == 0) {
  534.          var4 = "LIGHT_WEIGHT_POPUP";
  535.       } else if (this.lastPopupType == 1) {
  536.          var4 = "MEDIUM_WEIGHT_POPUP";
  537.       } else if (this.lastPopupType == 2) {
  538.          var4 = "HEAVY_WEIGHT_POPUP";
  539.       } else {
  540.          var4 = "";
  541.       }
  542.  
  543.       String var5 = this.lightWeightPopupEnabled ? "true" : "false";
  544.       return super.paramString() + ",desiredLocationX=" + this.desiredLocationX + ",desiredLocationY=" + this.desiredLocationY + ",label=" + var1 + ",lastPopupType=" + var4 + ",lightWeightPopupEnabled=" + var5 + ",margin=" + var3 + ",paintBorder=" + var2;
  545.    }
  546.  
  547.    private boolean popupFit(Rectangle var1) {
  548.       if (this.invoker != null) {
  549.          for(Container var2 = this.invoker.getParent(); var2 != null; var2 = ((Component)var2).getParent()) {
  550.             if (var2 instanceof JFrame || var2 instanceof JDialog || var2 instanceof JWindow) {
  551.                return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
  552.             }
  553.  
  554.             if (var2 instanceof JApplet) {
  555.                Rectangle var3 = ((Component)var2).getBounds();
  556.                Point var4 = ((Component)var2).getLocationOnScreen();
  557.                var3.x = var4.x;
  558.                var3.y = var4.y;
  559.                return SwingUtilities.isRectangleContainingRectangle(var3, var1);
  560.             }
  561.  
  562.             if (var2 instanceof Frame) {
  563.                return SwingUtilities.isRectangleContainingRectangle(((Component)var2).getBounds(), var1);
  564.             }
  565.          }
  566.       }
  567.  
  568.       return false;
  569.    }
  570.  
  571.    public void processKeyEvent(KeyEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  572.    }
  573.  
  574.    public void processMouseEvent(MouseEvent var1, MenuElement[] var2, MenuSelectionManager var3) {
  575.    }
  576.  
  577.    private void readObject(ObjectInputStream var1) throws IOException, ClassNotFoundException {
  578.       var1.defaultReadObject();
  579.       Vector var2 = (Vector)var1.readObject();
  580.       int var3 = 0;
  581.       int var4 = var2.size();
  582.       if (var3 < var4 && var2.elementAt(var3).equals("invoker")) {
  583.          ++var3;
  584.          this.invoker = (Component)var2.elementAt(var3);
  585.          ++var3;
  586.       }
  587.  
  588.       if (var3 < var4 && var2.elementAt(var3).equals("popup")) {
  589.          ++var3;
  590.          this.popup = (Popup)var2.elementAt(var3);
  591.          ++var3;
  592.       }
  593.  
  594.       if (var3 < var4 && var2.elementAt(var3).equals("frame")) {
  595.          ++var3;
  596.          this.frame = (Frame)var2.elementAt(var3);
  597.          ++var3;
  598.       }
  599.  
  600.    }
  601.  
  602.    static void recycleHeavyPopup(Popup var0) {
  603.       Object var1 = classLock;
  604.       synchronized(var1){}
  605.  
  606.       try {
  607.          Frame var4 = getFrame((Component)var0);
  608.          Hashtable var5 = getHeavyPopupCache();
  609.          Vector var3;
  610.          if (var5.containsKey(var4)) {
  611.             var3 = (Vector)var5.get(var4);
  612.          } else {
  613.             var3 = new Vector();
  614.             var5.put(var4, var3);
  615.             ((Window)var4).addWindowListener(new 1(var4));
  616.          }
  617.  
  618.          if (var3.size() < 5) {
  619.             var3.addElement(var0);
  620.          }
  621.       } catch (Throwable var7) {
  622.          throw var7;
  623.       }
  624.  
  625.    }
  626.  
  627.    static void recycleLightPopup(Popup var0) {
  628.       Object var1 = classLock;
  629.       synchronized(var1){}
  630.  
  631.       try {
  632.          Vector var3 = getLightPopupCache();
  633.          if (var3.size() < 5) {
  634.             var3.addElement(var0);
  635.          }
  636.       } catch (Throwable var5) {
  637.          throw var5;
  638.       }
  639.  
  640.    }
  641.  
  642.    static void recycleMediumPopup(Popup var0) {
  643.       Object var1 = classLock;
  644.       synchronized(var1){}
  645.  
  646.       try {
  647.          Vector var3 = getMediumPopupCache();
  648.          if (var3.size() < 5) {
  649.             var3.addElement(var0);
  650.          }
  651.       } catch (Throwable var5) {
  652.          throw var5;
  653.       }
  654.  
  655.    }
  656.  
  657.    static void recyclePopup(Popup var0) {
  658.       if (var0 instanceof JPanelPopup) {
  659.          recycleLightPopup(var0);
  660.       } else if (var0 instanceof WindowPopup) {
  661.          recycleHeavyPopup(var0);
  662.       } else if (var0 instanceof PanelPopup) {
  663.          recycleMediumPopup(var0);
  664.       }
  665.  
  666.    }
  667.  
  668.    private void registerMenuItemForAction(JMenuItem var1, Action var2) {
  669.       PropertyChangeListener var3 = this.createActionChangeListener(var1);
  670.       if (listenerRegistry == null) {
  671.          listenerRegistry = new Hashtable();
  672.       }
  673.  
  674.       listenerRegistry.put(var1, var3);
  675.       listenerRegistry.put(var3, var2);
  676.       var2.addPropertyChangeListener(var3);
  677.    }
  678.  
  679.    public void remove(int var1) {
  680.       if (var1 < 0) {
  681.          throw new IllegalArgumentException("index less than zero.");
  682.       } else if (var1 > ((Container)this).getComponentCount() - 1) {
  683.          throw new IllegalArgumentException("index greater than the number of items.");
  684.       } else {
  685.          Component var2 = ((Container)this).getComponent(var1);
  686.          if (var2 instanceof JMenuItem) {
  687.             this.unregisterMenuItemForAction((JMenuItem)var2);
  688.          }
  689.  
  690.          super.remove(var1);
  691.       }
  692.    }
  693.  
  694.    public void remove(Component var1) {
  695.       super.remove(var1);
  696.       if (var1 instanceof JMenuItem) {
  697.          JMenuItem var2 = (JMenuItem)var1;
  698.          this.unregisterMenuItemForAction(var2);
  699.       }
  700.  
  701.    }
  702.  
  703.    public void removePopupMenuListener(PopupMenuListener var1) {
  704.       super.listenerList.remove(class$javax$swing$event$PopupMenuListener != null ? class$javax$swing$event$PopupMenuListener : (class$javax$swing$event$PopupMenuListener = class$("javax.swing.event.PopupMenuListener")), var1);
  705.    }
  706.  
  707.    private void replacePopup(int var1) {
  708.       this.popup.removeComponent(this);
  709.       recyclePopup(this.popup);
  710.       this.popup = null;
  711.       switch (var1) {
  712.          case 0:
  713.             this.popup = this.createLightWeightPopup();
  714.             break;
  715.          case 1:
  716.             this.popup = this.createMediumWeightPopup();
  717.             break;
  718.          case 2:
  719.             this.popup = this.createHeavyWeightPopup();
  720.       }
  721.  
  722.       this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
  723.       this.popup.addComponent(this, "Center");
  724.       ((Container)this).invalidate();
  725.       this.popup.setBackground(((Component)this).getBackground());
  726.       this.popup.pack();
  727.    }
  728.  
  729.    public void setBorderPainted(boolean var1) {
  730.       this.paintBorder = var1;
  731.       ((Component)this).repaint();
  732.    }
  733.  
  734.    public static void setDefaultLightWeightPopupEnabled(boolean var0) {
  735.       SwingUtilities.appContextPut(defaultLWPopupEnabledKey, new Boolean(var0));
  736.    }
  737.  
  738.    public void setInvoker(Component var1) {
  739.       Component var2 = this.invoker;
  740.       this.invoker = var1;
  741.       if (var2 != this.invoker && super.ui != null) {
  742.          super.ui.uninstallUI(this);
  743.          super.ui.installUI(this);
  744.       }
  745.  
  746.       ((Container)this).invalidate();
  747.    }
  748.  
  749.    public void setLabel(String var1) {
  750.       String var2 = this.label;
  751.       this.label = var1;
  752.       ((JComponent)this).firePropertyChange("label", var2, var1);
  753.       if (super.accessibleContext != null) {
  754.          super.accessibleContext.firePropertyChange("AccessibleVisibleData", var2, var1);
  755.       }
  756.  
  757.       ((Container)this).invalidate();
  758.       ((Component)this).repaint();
  759.    }
  760.  
  761.    public void setLightWeightPopupEnabled(boolean var1) {
  762.       this.lightWeightPopupEnabled = var1;
  763.    }
  764.  
  765.    public void setLocation(int var1, int var2) {
  766.       if (this.popup != null) {
  767.          this.popup.setLocationOnScreen(var1, var2);
  768.       } else {
  769.          this.desiredLocationX = var1;
  770.          this.desiredLocationY = var2;
  771.       }
  772.  
  773.    }
  774.  
  775.    public void setPopupSize(int var1, int var2) {
  776.       if (this.popup != null) {
  777.          this.popup.setSize(var1, var2);
  778.       }
  779.  
  780.    }
  781.  
  782.    public void setPopupSize(Dimension var1) {
  783.       if (this.popup != null) {
  784.          this.popup.setSize(var1.width, var1.height);
  785.       }
  786.  
  787.    }
  788.  
  789.    public void setSelected(Component var1) {
  790.       SingleSelectionModel var2 = this.getSelectionModel();
  791.       int var3 = this.getComponentIndex(var1);
  792.       var2.setSelectedIndex(var3);
  793.    }
  794.  
  795.    public void setSelectionModel(SingleSelectionModel var1) {
  796.       this.selectionModel = var1;
  797.    }
  798.  
  799.    public void setUI(PopupMenuUI var1) {
  800.       super.setUI(var1);
  801.    }
  802.  
  803.    public void setVisible(boolean var1) {
  804.       if (var1 != this.isVisible()) {
  805.          if (!var1) {
  806.             this.getSelectionModel().clearSelection();
  807.          } else if (this.isPopupMenu()) {
  808.             if (this.getSubElements().length > 0) {
  809.                MenuElement[] var2 = new MenuElement[]{this, this.getSubElements()[0]};
  810.                MenuSelectionManager.defaultManager().setSelectedPath(var2);
  811.             } else {
  812.                MenuElement[] var6 = new MenuElement[]{this};
  813.                MenuSelectionManager.defaultManager().setSelectedPath(var6);
  814.             }
  815.          }
  816.  
  817.          if (var1) {
  818.             boolean var4 = this.ancestorIsModalDialog(this.invoker);
  819.             this.firePopupMenuWillBecomeVisible();
  820.             switch (this.lastPopupType) {
  821.                case 0:
  822.                   this.popup = this.createLightWeightPopup();
  823.                   break;
  824.                case 1:
  825.                   this.popup = this.createMediumWeightPopup();
  826.                   break;
  827.                case 2:
  828.                   this.popup = this.createHeavyWeightPopup();
  829.             }
  830.  
  831.             int var7 = this.lastPopupType;
  832.             this.popup.setLocationOnScreen(this.desiredLocationX, this.desiredLocationY);
  833.             this.popup.addComponent(this, "Center");
  834.             this.popup.setBackground(((Component)this).getBackground());
  835.             this.popup.pack();
  836.             Rectangle var5 = new Rectangle(this.desiredLocationX, this.desiredLocationY, this.popup.getWidth(), this.popup.getHeight());
  837.             byte var3;
  838.             if (this.popupFit(var5)) {
  839.                if (this.lightWeightPopupEnabled) {
  840.                   var3 = 0;
  841.                } else {
  842.                   var3 = 1;
  843.                }
  844.             } else if (var4) {
  845.                var3 = 1;
  846.             } else {
  847.                var3 = 2;
  848.             }
  849.  
  850.             if (this.invokerInHeavyWeightPopup(this.invoker)) {
  851.                var3 = 2;
  852.             }
  853.  
  854.             if (this.invoker == null) {
  855.                var3 = 2;
  856.             }
  857.  
  858.             if (var3 != var7) {
  859.                this.replacePopup(var3);
  860.                var7 = var3;
  861.             }
  862.  
  863.             this.lastPopupType = var7;
  864.             this.popup.show(this.invoker);
  865.          } else if (this.popup != null) {
  866.             this.firePopupMenuWillBecomeInvisible();
  867.             this.popup.hide();
  868.             this.popup.removeComponent(this);
  869.             recyclePopup(this.popup);
  870.             this.popup = null;
  871.          }
  872.  
  873.          if (super.accessibleContext != null) {
  874.             if (var1) {
  875.                super.accessibleContext.firePropertyChange("AccessibleState", (Object)null, AccessibleState.VISIBLE);
  876.             } else {
  877.                super.accessibleContext.firePropertyChange("AccessibleState", AccessibleState.VISIBLE, (Object)null);
  878.             }
  879.          }
  880.  
  881.       }
  882.    }
  883.  
  884.    public void show(Component var1, int var2, int var3) {
  885.       this.setInvoker(var1);
  886.       Frame var4 = getFrame(var1);
  887.       if (var4 != this.frame && var4 != null) {
  888.          this.frame = var4;
  889.          if (this.popup != null) {
  890.             this.setVisible(false);
  891.          }
  892.       }
  893.  
  894.       if (var1 != null) {
  895.          Point var5 = var1.getLocationOnScreen();
  896.          this.setLocation(var5.x + var2, var5.y + var3);
  897.       } else {
  898.          this.setLocation(var2, var3);
  899.       }
  900.  
  901.       this.setVisible(true);
  902.    }
  903.  
  904.    private void unregisterMenuItemForAction(JMenuItem var1) {
  905.       if (listenerRegistry != null) {
  906.          ActionChangedListener var2 = (ActionChangedListener)listenerRegistry.remove(var1);
  907.          if (var2 != null) {
  908.             Action var3 = (Action)listenerRegistry.remove(var2);
  909.             if (var3 != null) {
  910.                ((AbstractButton)var1).removeActionListener(var3);
  911.                var3.removePropertyChangeListener(var2);
  912.             }
  913.  
  914.             var2.setTarget((JMenuItem)null);
  915.          }
  916.       }
  917.  
  918.    }
  919.  
  920.    public void updateUI() {
  921.       this.setUI((PopupMenuUI)UIManager.getUI(this));
  922.    }
  923.  
  924.    private void writeObject(ObjectOutputStream var1) throws IOException {
  925.       Vector var2 = new Vector();
  926.       var1.defaultWriteObject();
  927.       if (this.invoker != null && this.invoker instanceof Serializable) {
  928.          var2.addElement("invoker");
  929.          var2.addElement(this.invoker);
  930.       }
  931.  
  932.       if (this.popup != null && this.popup instanceof Serializable) {
  933.          var2.addElement("popup");
  934.          var2.addElement(this.popup);
  935.       }
  936.  
  937.       if (this.frame != null && this.frame instanceof Serializable) {
  938.          var2.addElement("frame");
  939.          var2.addElement(this.frame);
  940.       }
  941.  
  942.       var1.writeObject(var2);
  943.       if (super.ui != null && this.getUIClassID().equals("PopupMenuUI")) {
  944.          super.ui.installUI(this);
  945.       }
  946.  
  947.    }
  948. }
  949.